-- read each line and print

--[[ refer
http://stackoverflow.com/questions/11201262/how-to-read-data-from-a-file-in-lua
http://stackoverflow.com/questions/21416798/lua-global-variable-containing-path-to-current-file

--]]

-- local info = debug.getinfo(1,'S')
-- print(info.source:sub(2))

function file_exist (file)
    local f = io.open(file,'rb')
    if f then f:close() end
    return f ~= nil
end

function print_lines(file)
    if not file_exist(file) then print('file not exists') end
    local linenum=1
    for line in io.lines(file) do
        print(linenum .. ' '.. line)
        linenum = linenum + 1
    end
end

print_lines('/home/wzq/workspace/lua_snippet/read_file.lua')